// src.helper.httpUtil.js


var request = require('request');
var querystring=require('querystring');
var fs =  require('fs');
var log  = require('log4js').getLogger("HttpUtils");

module.exports = {
    get:function(url, callback){
        request(url, function (error, response, data) {
            if (!error && response.statusCode == 200) {
                log.info('url:【'+url + '】response:【'+data+'】');
                callback(error, JSON.parse(data));
            }else {
                log.error('【请求地址】:"'+url+'" |【response.statusCode】:'+response.statusCode+' | 【error】:'+error+'');
                callback(error);
            }
        })
    },
    post:function(url, params, callback){
        var postData = querystring.stringify(params);
        request.post(url, function (error, response, data) {
            if (!error && response.statusCode == 200) {
                log.info('url:【'+url + '】response:【'+data+'】');
                callback(error, JSON.parse(data));
            }else {
                log.error('【请求地址】:"'+url+'" |【response.statusCode】:'+response.statusCode+' | 【error】:'+error+'');
                callback(error);
            }
        }).form(postData);
    }
};